package hlhj.fhp.checkpoint.module

import android.content.Context
import com.example.mymvp.mvp.BaseModule
import com.lzy.okgo.model.Response
import hlhj.fhp.checkpoint.http.Apis
import hlhj.fhp.checkpoint.http.CustomAction
import hlhj.fhp.checkpoint.http.LoadingAction
import hlhj.fhp.checkpoint.javaBean.LimitBean
import hlhj.fhp.checkpoint.javaBean.LocationBean
import hlhj.fhp.checkpoint.javaBean.MyBaseBean
import hlhj.fhp.checkpoint.javaBean.PlateBean

/**
 * Created by Never Fear   on 2018\11\8 0008.
Never More....
 */
class AddCarModule :BaseModule {

    var listener:AddCarResp?=null
    //根据地区获取该地区限制
    fun getLimit(city_prefix:String,plate_prefix:String,c:Context){
        Apis.getLimit(city_prefix, plate_prefix)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<LimitBean>>(c){
                                override fun httpSuccess(t: Response<LimitBean>) {
                                    listener?.setLimit(t.body())
                                }
                            })
                }
    }
    //获取所有颜色车牌
    fun getAllPlate(c:Context){
        Apis.getAllPlate()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<PlateBean>>(c){
                                override fun httpSuccess(t: Response<PlateBean>) {
                                    listener?.allPlateResp(t.body())
                                }
                            })
                }
    }

    //添加违章车辆
    fun addCar(id:Int,plate_number:String,vin:String,engine_number:String,car_type:String,car_owner:String,owner_phone:String,plate_type:String,city:String,c:Context,registno:String,city_id:String){
        Apis.addCar(id,plate_number,vin,engine_number,car_type,car_owner,owner_phone,plate_type,city,registno,city_id)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<MyBaseBean>>(c){
                                override fun httpSuccess(t: Response<MyBaseBean>) {
                                    listener?.addResult(t.body())
                                }
                            })
                }
    }
    //获取地区缩写
    fun getCity(c:Context){
        Apis.getCity()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<LocationBean>>(c){
                                override fun httpSuccess(t: Response<LocationBean>) {
                                    listener?.cityResp(t.body())
                                }
                            })
                }
    }
    interface AddCarResp{
        fun allPlateResp(plateBean: PlateBean)
        fun addResult(myBaseBean: MyBaseBean)
        fun cityResp(locationBean: LocationBean)
        fun setLimit(limitBean: LimitBean)
    }
}